<?
if (!$module) fusedie("No module chosen");
if (!$_SERVER["PATH_INFO"]) {
	#fusedie("No PATH_INFO");
	$uri = $_SERVER["SCRIPT_NAME"];
	$uri = str_replace(".php","",$uri);
	header("Location: $uri/"); die;
	}

$url = $_SERVER["PATH_INFO"];
$url = preg_replace("/\/$/","/index.php",$url);
$url = preg_replace("/^\//","",$url);
$values = explode("/",$url);

$fname = array_pop($values);

if (!isset($params)) $params = array();
$modules = array($module);

$uri = strstr($_SERVER["HTTP_PROTOCOL"],"HTTPS")?"https://{$_SERVER["HTTP_HOST"]}":"http://{$_SERVER["HTTP_HOST"]}";

$uri .= $_SERVER["SCRIPT_NAME"]."/";

$uri = str_replace(".php","",$uri);

$p = array_merge($params,array(
	"uri"=>$uri,
	"module"=>$module,
	"value"=>$value,
	));
if (inc_exists("$module/skin.php"))
$p = array_merge($p,inc_incfile("$module/skin.php",$p));
skin_trail($p);

foreach ($values as $value)
	{	
	$params["module"] = $module;
	$params["value"] = $value;
	list($module,$params) = inc_incfile("$module/sub.php",$params);
	
	$uri.="$value/";
	$modules[] = $module;
	
	$p = array_merge($params,array(
		"uri"=>$uri,
		"module"=>$module,
		"value"=>$value,
		));
		
	if (inc_exists("$module/skin.php"))
	$p = array_merge($p,inc_incfile("$module/skin.php",$p));
	skin_trail($p);
	}

ob_start();
if (inc_exists("$module/$fname",$params)) {
	inc_incfile("$module/$fname",$params);
	}
else  {
	$params["fname"] = $fname;
	inc_incfile("$module/default.php",$params); 
	}
$contents = ob_get_contents();
ob_end_clean();

if ($_skin["disable"] == true)
	$skin="%%";
	else
	{
	ob_start();
	if (!$_skin["fname"]) $_skin["fname"] = "index.php";
	include $skindir."/".$_skin["fname"];
	$skin = ob_get_contents();
	ob_end_clean();
	}
$skin = str_replace("src=\"","src=\"$skinurl/",$skin);
$skin = str_replace("background=\"","background=\"$skinurl/",$skin);
$skin = str_replace("url(\"","url(\"$skinurl/",$skin);

#NAPXP
#$contents = str_replace("site://","$topurl/",$contents);

echo str_replace("%%",$contents,$skin);
?>
